# 41. CPU算力分配

41 41-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let input = [];
rl.on('line', function(num) {
    input.push(num);
});
rl.on('close', () => {
    const [serverCountGroupA, serverCountGroupB] = input[0].split(' ').map(Number);
    let totalPowerGroupA = 0;
    let powerGroupA = input[1].split(' ').map(Number);
    totalPowerGroupA = powerGroupA.reduce((a, b) => a+b, 0);

    let totalPowerGroupB = 0;
    let powerCountGroupB = {};
    const powers = iniput[2].split(' ').map(Number);
    for(let power of powers) {
        totalPowerGroupB += power;
        if (powerCountGroupB[power]) {
            powerCountGroupB[power] += 1; 
        } else {
            powerCountGroupB[power] = 1; 
        }
    }
    let diff = Math.round((totalPowerGroupA - totalPowerGroupB)/2);
    powerGroupA.sort((a, b)=>a-b);
    for(let powerA of powerGroupA) {
        let powerB = powerA - diff;
        if (powerCountGroupB[powerB]) {
            console.log(powerA + ' ' + powerB);
            break;
        }
    }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36